package com.bwie.car.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.car.service.CarService;
import com.bwie.common.domain.Car;
import com.bwie.common.domain.request.CarRequest;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/car")
@Slf4j
public class CarController {

    @Autowired
    private CarService carService;

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/showCar")
    public Result<PageResult<Car>> showCar(@RequestBody CarRequest carRequest){
        log.info("功能名称:汽车列表,请求URI:{},请求方式:{},请求参数:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(carRequest));
        Result<PageResult<Car>> result = carService.showCar(carRequest);
        log.info("功能名称:汽车列表,请求URI:{},请求方式:{},响应结果:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(result));
        return result;
    }


    @PostMapping("/findById")
    public Result findByPhone(@RequestParam String carId){
        log.info("功能名称:贷款回显,请求URI:{},请求方式:{},请求参数:{}",
                request.getRequestURI(),
                request.getMethod(),
               carId);
        Result byId = carService.findById(carId);
        log.info("功能名称:贷款回显,请求URI:{},请求方式:{},响应结果:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(byId));
        return byId;
    }

    @PostMapping("/reply")
    public Result reply(@RequestParam Integer carId){
        log.info("功能名称:贷款回显,请求URI:{},请求方式:{},请求参数:{}",
                request.getRequestURI(),
                request.getMethod(),
                carId);
        Result reply = carService.reply(carId);
        log.info("功能名称:贷款回显,请求URI:{},请求方式:{},响应结果:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(reply));

        return reply;
    }




}
